﻿using Xejen.Communication.Http.Abstract;
using Xejen.Communication.Http.Communicator;
using Xejen.Hosting.Extensions;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Text;

namespace Xejen.Communication.Http.Extensions
{
    /// <summary>
    /// 针对<see cref="IHttpCommunicatorBuilder"/>进行扩展
    /// </summary>
    public static class HttpCommunicatorBuilderExtensions
    {
        /// <summary>
        /// 添加Http通讯器
        /// </summary>
        /// <returns></returns>
        public static IHttpCommunicatorBuilder AddCommunicator(this IHttpCommunicatorBuilder builder)
        {
            var logger = builder.LoggerManager.CreateLogger(typeof(HttpCommunicatorBuilderExtensions));
            builder.Host.AddServices((services) =>
            {
                services.AddSingleton<IHttpInvokerCreator<WebRequestInvoker>, WebRequestInvokerCreator>();
                services.AddSingleton<IHttpCommunicator, HttpCommunicator<WebRequestInvoker>>();
            });
            logger.LogInformation($"完成Http通讯器构建");
            return builder;
        }
    }
}
